﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.SharpZipLib.Zip.Compression;
using System.IO;

namespace WoWConnecter
{
    public class RealmPacketOut : BasicPacketOut
    {
        public override int HeaderSize
        {
            get
            {
                return 2;
            }
        }

        public RealmPacketOut()
            : base((int)0)
        {

        }

        public RealmPacketOut(RealmServerOpCode opcode)
            : base((int)opcode)
        {
            WriteUShortBE(0);
            WriteInt(0);
        }

        public void CompressInto(BasicPacketOut packet)
        {
            byte[] rawData = (BaseStream as MemoryStream).ToArray();
            byte[] compressed = new byte[rawData.Length];
            int deflatedLength = 0;

            Compression.CompressZLib(rawData, compressed, 7, out deflatedLength);
            packet.Write(deflatedLength);
            Array.Resize<byte>(ref compressed, deflatedLength);
            packet.Write(compressed);
        }
    }
}
